package com.lin.Imp;
import com.lin.mapper.MoneyMapper;
import com.lin.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MoneyServiceImpl implements MoneyService{
    @Autowired
    private MoneyMapper moneyMapper;

    @Override
    public Map<String, Object> getTIStatistics() {
        Map<String, Object> result = new HashMap<>();

        // 获取平均时间
        Double avg = moneyMapper.selectAverageTime();
        result.put("avg", avg != null ? avg.intValue() : 0);

        // 获取订单数据
        List<Map<String, Object>> orders = moneyMapper.selectOrderTimes();

        // 提取订单ID和时间
        List<String> orderIds = orders.stream()
                .map(order -> order.get("orderId").toString())
                .collect(Collectors.toList());

        List<Integer> totalTimes = orders.stream()
                .map(order -> (Integer) order.get("totalTime"))
                .collect(Collectors.toList());

        result.put("data_Formid", orderIds);
        result.put("data_totaltime", totalTimes);

        return result;
    }
}
